/*package com.znf4.controller.sett;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSON;
import com.bigpay.account.entity.RpRemitApplication;
import com.bigpay.account.entity.RpSettRecord;
import com.bigpay.account.enums.SettModeTypeEnum;
import com.bigpay.account.enums.SettRecordStatusEnum;
import com.bigpay.account.service.RpAccountService;
import com.bigpay.account.service.RpRemitApplicationService;
import com.bigpay.account.service.RpSettHandleService;
import com.bigpay.account.service.RpSettQueryService;
import com.bigpay.account.vo.RpSettRecordVo;
import com.bigpay.account.vo.SumSettAmountVo;
import com.bigpay.common.core.config.SystemConfig;
import com.bigpay.common.core.entity.ApiCommonResultVo;
import com.bigpay.common.core.exception.BizException;
import com.bigpay.common.core.page.PageBean;
import com.bigpay.common.core.page.PageParam;
import com.bigpay.common.core.utils.ProxyPayXlsUtils;
import com.bigpay.common.core.utils.StringUtil;
import com.bigpay.user.entity.RpUserInfo;
import com.bigpay.user.enums.BankAccountTypeEnum;
import com.bigpay.user.enums.CardTypeEnum;
import com.znf4.controller.common.BaseController;
import com.znf4.controller.common.ConstantClass;
import com.znf4.controller.common.JSONParam;

*//**
 * 结算信息 
 *//*
@Controller
@RequestMapping("/merchant/sett")
public class SettController extends BaseController {
	private static final Log LOG = LogFactory.getLog(SettController.class);
	@Autowired
	private RpSettHandleService rpSettHandleService;
	@Autowired
	private RpSettQueryService rpSettQueryService;
	@Autowired
	private RpAccountService rpAccountService;
	@Autowired
	private RpRemitApplicationService rpRemitApplicationService;

	*//**
	 * 函数功能说明 ： 查询结算记录
	 * 
	 * @参数： @return
	 * @return String
	 * @throws
	 *//*
	@RequestMapping(value = "/getSettList", method = { RequestMethod.POST, RequestMethod.GET })
	public String getAccountInfo(HttpServletRequest request) {

		return "sett/list";
	}

	@RequestMapping(value = "/ajaxSettList", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String ajaxPaymentList(HttpServletRequest request, @RequestBody JSONParam[] params) throws IllegalAccessException, InvocationTargetException {
		// convertToMap定义于父类，将参数数组中的所有元素加入一个HashMap
		HashMap<String, String> paramMap = convertToMap(params);
		String sEcho = paramMap.get("sEcho");
		int start = Integer.parseInt(paramMap.get("iDisplayStart"));
		int length = Integer.parseInt(paramMap.get("iDisplayLength"));
		String beginDate = paramMap.get("beginDate");
		String endDate = paramMap.get("endDate");
		if (StringUtil.isEmpty(beginDate) && !StringUtil.isEmpty(endDate)) {
			beginDate = endDate;
		}
		if (StringUtil.isEmpty(endDate) && !StringUtil.isEmpty(beginDate)) {
			endDate = beginDate;
		}
		String merchantRequestNo = paramMap.get("merchantRequestNo");
		String status = paramMap.get("status");
		RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);

		// 页面当前页需要显示的记录数据
		PageParam pageParam = new PageParam(start / length + 1, length);
		Map<String, Object> settMap = new HashMap<String, Object>();
		settMap.put("userNo", userInfo.getUserNo());
		settMap.put("settStatus", status);
		settMap.put("merchantRequestNo", merchantRequestNo);
		settMap.put("beginDate", beginDate);
		settMap.put("endDate", endDate);
		PageBean pageBean = rpSettQueryService.querySettRecordListPage(pageParam, settMap);
		List<Object> recordList = pageBean.getRecordList();
		List<Object> voList = new ArrayList<>();
		for (Object obj : recordList) {
			RpSettRecord record = (RpSettRecord) obj;
			RpSettRecordVo vo = new RpSettRecordVo();
			BeanUtilsBean beanUtilsBean = new BeanUtilsBean();
			// beanUtilsBean.getConvertUtils().register(new
			// org.apache.commons.beanutils.converters.BigDecimalConverter(null),
			// BigDecimal.class);
			beanUtilsBean.getConvertUtils().register(new org.apache.commons.beanutils.converters.DateConverter(null), java.util.Date.class);
			beanUtilsBean.copyProperties(vo, record);
			voList.add(vo);
		}
		pageBean.setRecordList(voList);
		Long count = Long.valueOf(pageBean.getTotalCount() + "");

		String jsonString = JSON.toJSONString(pageBean.getRecordList());
		String json = "{\"sEcho\":" + sEcho + ",\"iTotalRecords\":" + count.longValue() + ",\"iTotalDisplayRecords\":" + count.longValue() + ",\"aaData\":" + jsonString + "}";
		return json;
	}

	@RequestMapping(value = "/launchSett", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ApiCommonResultVo launchSett(HttpServletRequest request) throws IllegalAccessException, InvocationTargetException {
		RpUserInfo rpUserInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		String settAmount = request.getParameter("settAmount");
		try {
			rpSettHandleService.launchSett(rpUserInfo.getUserNo(), new BigDecimal(settAmount));
		} catch (BizException e) {
			return new ApiCommonResultVo(-1, e.getMsg(), "");
		}
		return new ApiCommonResultVo(0, "操作成功", "");
	}

	@RequestMapping(value = "/sumAmountByUserNo", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public SumSettAmountVo sumAmountByUserNo(HttpServletRequest request) {
		RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		String beginDate = request.getParameter("beginDate");
		String endDate = request.getParameter("endDate");
		String merchantRequestNo = request.getParameter("merchantRequestNo");
		String status = request.getParameter("status");
		if (StringUtil.isEmpty(beginDate) && !StringUtil.isEmpty(endDate)) {
			beginDate = endDate;
		}
		if (StringUtil.isEmpty(endDate) && !StringUtil.isEmpty(beginDate)) {
			endDate = beginDate;
		}
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userNo", userInfo.getUserNo());
		params.put("beginDate", beginDate);
		params.put("endDate", endDate);
		params.put("merchantRequestNo", merchantRequestNo);
		params.put("settStatus", status);
		return rpSettQueryService.sumAmountByUserNo(params);
	}

	*//**
	 * 导出结算记录报表
	 * 
	 * @throws IOException
	 *//*
	@RequestMapping(value = "/listSettRecordExportExecl", method = { RequestMethod.POST, RequestMethod.GET })
	public void listSettRecordExportExecl(HttpServletRequest request, HttpServletResponse response) throws IOException {
		RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		response.setCharacterEncoding("utf-8");
		File file = null;
		FileOutputStream out = null;
		int start = 1;
		int length = 10;
		try {

			String beginDate = request.getParameter("beginDate");
			String endDate = request.getParameter("endDate");
			String merchantRequestNo = request.getParameter("merchantRequestNo");
			String status = request.getParameter("status");
			if (StringUtil.isEmpty(beginDate) && !StringUtil.isEmpty(endDate)) {
				beginDate = endDate;
			}
			if (StringUtil.isEmpty(endDate) && !StringUtil.isEmpty(beginDate)) {
				endDate = beginDate;
			}

			String fileName = SystemConfig.RECONCILIATION_DOWNLOAD_DIR + userInfo.getUserName() + "_sett.csv";
			file = new File(fileName);
			if (!file.exists()) {
				file.createNewFile();
			} else {
				file.delete();
				file.createNewFile();
			}
			// 页面当前页需要显示的记录数据
			PageParam pageParam = new PageParam(start / length + 1, length);
			Map<String, Object> settMap = new HashMap<String, Object>();
			settMap.put("userNo", userInfo.getUserNo());
			settMap.put("settStatus", status);
			settMap.put("merchantRequestNo", merchantRequestNo);
			settMap.put("beginDate", beginDate);
			settMap.put("endDate", endDate);
			PageBean pageBean = rpSettQueryService.querySettRecordListPage(pageParam, settMap);
			List<Object> recordList = pageBean.getRecordList();

			int pageNum = 1; // 当前页
			int pageCount = 1; // 总页数
			pageCount = pageBean.getTotalPage();
			StringBuffer str = new StringBuffer();
			str.append("创建时间,商户请求号,结算金额,结算手续费,银行名称,开户名,开户账户,结算状态");
			str.append("\n");
			for (Object obj : recordList) {
				RpSettRecord settRecord = (RpSettRecord) obj;
				str.append(settRecord.getCreateTimeDesc()).append(",");
				str.append("\t" + settRecord.getMerchantRequestNo()).append("\t,");
				str.append("\t" + settRecord.getSettAmount().doubleValue()).append("\t,");
				str.append("\t" + settRecord.getSettFee().doubleValue()).append("\t,");
				str.append(settRecord.getBankName()).append(",");
				str.append(settRecord.getBankAccountName()).append(",");
				str.append("\t" + settRecord.getBankAccountNo()).append("\t,");
				str.append(settRecord.getSettStatusDesc()).append(",");
				str.append("\n");
			}
			// 加上UTF-8文件的标识字符
			out = new FileOutputStream(new File(fileName));
			out.write(new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF });
			out.write(str.toString().getBytes());

			for (pageNum = 2; pageNum <= pageCount; pageNum++) {

				// 情况str的内容
				str.setLength(0);
				pageBean = rpSettQueryService.querySettRecordListPage(new PageParam(pageNum, length), settMap);
				recordList = pageBean.getRecordList();

				if (recordList == null || recordList.isEmpty()) {
					break;
				}
				for (Object obj : recordList) {
					RpSettRecord settRecord = (RpSettRecord) obj;
					str.append(settRecord.getCreateTimeDesc()).append(",");
					str.append("\t" + settRecord.getMerchantRequestNo()).append("\t,");
					str.append("\t" + settRecord.getSettAmount().doubleValue()).append("\t,");
					str.append("\t" + settRecord.getSettFee().doubleValue()).append("\t,");
					str.append(settRecord.getBankName()).append(",");
					str.append(settRecord.getBankAccountName()).append(",");
					str.append("\t" + settRecord.getBankAccountNo()).append("\t,");
					str.append(settRecord.getSettStatusDesc()).append(",");
					str.append("\n");
				}
				out.write(new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF });
				out.write(str.toString().getBytes());
			}

			this.download(fileName, response);
		} catch (IOException e) {
			LOG.error("IO", e);
		} finally {
			if (out != null) {
				out.flush();
				out.close();
			}

		}
	}

	*//**
	 * 下载csv文件
	 * 
	 * @param path
	 * @param response
	 *//*
	private void download(String path, HttpServletResponse response) {
		try {
			// path是指欲下载的文件的路径。
			File file = new File(path);
			// 取得文件名。
			String filename = file.getName();
			// 以流的形式下载文件。
			InputStream fis = new BufferedInputStream(new FileInputStream(path));
			byte[] buffer = new byte[fis.available()];
			fis.read(buffer);
			fis.close();
			// 清空response
			response.reset();
			// 设置response的Header
			response.addHeader("Content-Disposition", "attachment;filename=" + new String(filename.getBytes()));
			response.addHeader("Content-Length", "" + file.length());
			OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
			response.setContentType("application/vnd.ms-excel;charset=utf-8");
			toClient.write(buffer);
			toClient.flush();
			toClient.close();
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	*//**
	 * 函数功能说明：excel上传.
	 * 
	 * @return void
	 * @throws
	 *//*
	@RequestMapping(value = "/importExcel", method = { RequestMethod.POST, RequestMethod.GET })
	public void importExcel(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws IOException {
		RpUserInfo userInfo = (RpUserInfo) request.getSession().getAttribute(ConstantClass.USER);
		StringBuffer buffer = new StringBuffer("");
		if (!file.isEmpty()) {
			String name = file.getOriginalFilename();
			String str = name.split("\\.")[1];
			if ("xls".equals(str) || "xlsx".equals(str)) {
				for (String[] strArray : ProxyPayXlsUtils.rosolveFile(file.getInputStream(), str, 3)) {
					RpRemitApplication remit = new RpRemitApplication();
					remit.setId(StringUtil.get32UUID());
					remit.setPayKey(userInfo.getUserNo());
					if(StringUtil.isEmpty(strArray[1])){
						String remitRequestNo = rpAccountService.buildRemitRequestNo();
						remit.setOutTradeNo(remitRequestNo);
					}else{
						remit.setOutTradeNo(strArray[1]);
					}
					//银行卡号
					if(StringUtil.isEmpty(strArray[2])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setBankAccountNo(strArray[2]);
					}
					//银行账户名
					if(StringUtil.isEmpty(strArray[3])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setBankAccountName(strArray[3]);
					}
					//银行卡类型
					if(StringUtil.isEmpty(strArray[4])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						String bankAccountType = BankAccountTypeEnum.PRIVATE_DEBIT_ACCOUNT.name();
						if ("2".equals(strArray[4])) {
							bankAccountType = BankAccountTypeEnum.PUBLIC_ACCOUNT.name();
						}
						remit.setBankAccountType(bankAccountType);
					}
					//代付金额
					if(StringUtil.isEmpty(strArray[5])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setSettAmount(new BigDecimal(strArray[5]));
					}
					//手机号
					if(StringUtil.isEmpty(strArray[6])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setPhoneNo(strArray[6]);
					}
					//银行名
					if(StringUtil.isEmpty(strArray[7])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setBankName(strArray[7]);
					}
					//联行号
					if(StringUtil.isEmpty(strArray[8])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setBankBranchNo(strArray[8]);
						remit.setBankClearNo(strArray[8]);
						remit.setBankCode(strArray[8].substring(0, 3));
					}
					//支行名称
					if(StringUtil.isEmpty(strArray[9])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setBankBranchName(strArray[9]);
					}
					//交易类型
					if(StringUtil.isEmpty(strArray[10])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setProxyType(strArray[10]);
					}
					//产品类型
					if(StringUtil.isEmpty(strArray[11])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setProductType(strArray[11]);
					}
					//开户行所在省
					if(StringUtil.isEmpty(strArray[12])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setProvince(strArray[12]);
					}
					//开户行所在市
					if(StringUtil.isEmpty(strArray[13])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setCity(strArray[13]);
					}
					//开户人身份证
					if(StringUtil.isEmpty(strArray[14])){
						//为空，记录失败
						buffer.append(strArray[0]).append(",");
						continue;
					}else{
						remit.setCardType(CardTypeEnum.IDENTITY.name());
						remit.setCardNo(strArray[14]);
					}
					//状态
					remit.setStatus(SettRecordStatusEnum.WAIT_CONFIRM.name());
					rpRemitApplicationService.saveRemitApplication(remit);
				}
			}

		}

	}

	public static void main(String[] args) {
		String url = "H:/商户代付文件模版.xls";
		File file = new File(url);
		if (file.exists()) {
			String name = file.getName();
			String str = name.split("\\.")[1];
			if ("xls".equals(str) || "xlsx".equals(str)) {
				List<RpSettRecord> settRecordList = new ArrayList<RpSettRecord>();
				try {
					InputStream is = new FileInputStream(file);
					for (String[] strArray : ProxyPayXlsUtils.rosolveFile(is, str, 2)) {
						RpSettRecord record = new RpSettRecord();
						record.setId(StringUtil.get32UUID());
						record.setSettMode(SettModeTypeEnum.SELFHELP_SETTLE.name());// 手动结算
						record.setAccountNo("session中获取");
						record.setUserNo("session中获取");
						record.setUserName("session中获取");
						record.setUserType("session中获取");
						record.setSettDate(new Date());
						record.setBankCode(strArray[8].substring(0, 3));
						record.setBankName(strArray[7]);
						record.setBankAccountName(strArray[3]);
						record.setBankAccountNo(strArray[2]);
						String bankAccountType = BankAccountTypeEnum.PRIVATE_DEBIT_ACCOUNT.name();
						if ("2".equals(strArray[4])) {
							bankAccountType = BankAccountTypeEnum.PUBLIC_ACCOUNT.name();
						}
						record.setBankAccountType(bankAccountType);
						record.setCountry("中国");
						record.setProvince(strArray[12]);
						record.setCity(strArray[13]);
						record.setAreas(strArray[13]);
						record.setBankAccountAddress(strArray[9]);
						record.setMobileNo(strArray[6]);
						record.setSettAmount(new BigDecimal(strArray[5]));
						record.setSettFee(BigDecimal.ZERO);
						record.setRemitAmount(record.getSettAmount());
						record.setSettStatus(SettRecordStatusEnum.WAIT_CONFIRM.name());
						record.setRemitRequestTime(new Date());
						record.setBankChannelCode("银行通道编码");
						record.setBankChannelName("银行通道名称");
						record.setPlatCost(BigDecimal.ZERO);// "平台成功" TODO
						record.setRemitRequestNo("");
						record.setTrxNo(record.getRemitRequestNo());
						record.setSettType(strArray[10]);
						record.setMerchantRequestNo(strArray[1]);
						record.setPayTypeCode(strArray[11]);
						record.setProxyChannelCode("代付通道编码");
						record.setProxyChannelName("代付通道名称");
						record.setCardType(CardTypeEnum.IDENTITY.name());
						record.setCardNo(strArray[14]);
						settRecordList.add(record);
						System.out.println(record.toString());
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	
	
}
*/